﻿using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Text;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;
using Microsoft.ApplicationBlocks.Data;

namespace AnyOffice.general.system.menu
{
    public partial class func : ModulePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["menu_id"] != null)
            {
                string menuId = Request.QueryString["menu_id"].ToString();
                this.ViewState["MenuId"] = menuId;
                DataTable table = new SysMenuDao().SelectByMenuId(base.Conn, menuId);
                if (table.Rows.Count > 0)
                {
                    this.imgFunc.ImageUrl = "/images/menu/" + table.Rows[0]["Image"].ToString() + ".gif";
                    this.litFuncName.Text = table.Rows[0]["MenuName"].ToString();
                }
                StringBuilder builder = new StringBuilder();
                string commandText = "select * from [dbo].[sys_function] where len(MenuId)=4 and left(MenuID,2) ='" + menuId + "' order by MenuId asc, FuncId asc";
                DataTable table2 = SqlHelper.ExecuteDataset(base.Conn, CommandType.Text , commandText).Tables[0];
                if (table2.Rows.Count > 0)
                {
                    for (int i = 0; i < table2.Rows.Count; i++)
                    {
                        builder.Append("<tr class=\"TableData\">\n");
                        builder.Append("  <td nowrap title=\"" + table2.Rows[i]["FuncName"].ToString() + "\" >\n");
                        builder.Append("    <img src=\"/images/menu/" + table2.Rows[i]["FuncImg"].ToString() + ".gif\" align=\"absmiddle\">&nbsp;" + table2.Rows[i]["MenuId"].ToString() + "&nbsp;<b>" + table2.Rows[i]["FuncName"].ToString() + "</b>");
                        builder.Append("  </td>");
                        builder.Append("  <td nowrap align=\"center\">");
                        builder.Append("    <a href=\"func_edit.aspx?func_id=" + table2.Rows[i]["FuncId"].ToString() + "\"> 编辑</a>&nbsp;&nbsp;");
                        builder.Append("    <a href=\"javascript:delete_menu('" + table2.Rows[i]["MenuId"].ToString() + "','" + table2.Rows[i]["FuncId"].ToString() + "','" + table2.Rows[i]["FuncName"].ToString() + "');\"> 删除</a>");
                        builder.Append("  </td>");
                        string str3 = "select * from [dbo].[sys_function] where len(MenuID)=6 and left(MenuID,4) ='" + table2.Rows[i]["MenuId"].ToString() + "' order by MenuID asc, FuncID asc";
                        DataTable table3 = SqlHelper.ExecuteDataset(base.Conn, CommandType.Text, str3).Tables[0];
                        if (table3.Rows.Count > 0)
                        {
                            for (int j = 0; j < table3.Rows.Count; j++)
                            {
                                builder.Append("<tr class=\"TableData\">\n");
                                builder.Append("  <td nowrap title=\"" + table3.Rows[j]["FuncName"].ToString() + "\" >\n");
                                builder.Append("    &nbsp;&nbsp;&nbsp;&nbsp;");
                                builder.Append("    <img src=\"/images/menu/" + table3.Rows[j]["FuncImg"].ToString() + ".gif\" align=\"absmiddle\">&nbsp;" + table3.Rows[j]["MenuId"].ToString() + "&nbsp;<b>" + table3.Rows[j]["FuncName"].ToString() + "</b>");
                                builder.Append("  </td>");
                                builder.Append("  <td nowrap align=\"center\">");
                                builder.Append("    <a href=\"func_edit.aspx?func_id=" + table3.Rows[j]["FuncId"].ToString() + "\"> 编辑</a>&nbsp;&nbsp;");
                                builder.Append("    <a href=\"javascript:delete_menu('" + table3.Rows[j]["MenuId"].ToString() + "','" + table3.Rows[j]["FuncId"].ToString() + "','" + table3.Rows[j]["FuncName"].ToString() + "');\"> 删除</a>");
                                builder.Append("  </td>");
                            }
                        }
                        builder.Append("  </td>\n");
                        builder.Append("</tr>\n");
                    }
                }
                builder.Append("</table>\n");
                builder.Append("  </td>\n");
                builder.Append("</tr>\n");
                builder.Append("</table>\n");
                this.litFunc.Text = builder.ToString();
            }
        } 

    }
}
